package com.lemon.soft.bookingroom.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.lemon.soft.bookingroom.dto.BookingCreateDTO;
import com.lemon.soft.bookingroom.dto.BookingQueryDTO;
import com.lemon.soft.bookingroom.entity.MeetingRoomsEntity;
import com.lemon.soft.bookingroom.service.MeetingRoomsService;
import com.lemon.soft.bookingroom.util.PageUtils;
import com.lemon.soft.bookingroom.util.R;
import com.lemon.soft.bookingroom.vo.BookingVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lemon.soft.bookingroom.entity.BookingsEntity;
import com.lemon.soft.bookingroom.service.BookingsService;


/**
 * 
 *
 * @author ${author}
 * @email ${email}
 * @date 2025-05-29 12:38:52
 */

@CrossOrigin
@Tag(name = "预约管理")
@Slf4j
@RestController
@RequestMapping("bookingroom/bookings")
public class BookingsController {
    @Autowired
    private BookingsService bookingsService;
    @Autowired
    private MeetingRoomsService meetingRoomsService;

    @Operation(summary = "查询可用的会议室")
    @PostMapping("/query")
    public R queryAvailableRooms(@RequestBody BookingQueryDTO queryDTO) {
        log.error("queryDTO: {}", queryDTO);
        List<MeetingRoomsEntity> rooms = bookingsService.queryAvailableRooms(queryDTO);

        return R.ok().put("rooms", rooms);
    }

    @Operation(summary = "创建预约")
    @PostMapping("/create/{userId}")
    public R createBooking(@RequestBody BookingCreateDTO createDTO,
                           @PathVariable("userId") Integer userId) {
        Object result = bookingsService.createBooking(createDTO, userId);
        return R.ok().put("data", result);
    }

    @Operation(summary = "支付")
    @PostMapping("/pay/{bookingId}")
    public R processPayment( @PathVariable("bookingId") Integer bookingId) {
        String success = bookingsService.processPayment(bookingId);
        return R.ok().put("data", success);
    }
    /**
     * 列表
     */
    @Operation(summary = "所有生成的预定信息列表")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = bookingsService.queryPage(params);

        return R.ok().put("page", page);
    }


}
